# fake.creature模块

from model.creature import Creature 
from error import Missing, Duplicate 



_creatures = [
    Creature(
        name='Yeti', 
        country='CN', 
        area='Himalayas', 
        description='Hirsute Himalayan', 
        aka='Abominable Snowman'
    ), 
    Creature(
        name='Bigfoot', 
        description='Yrti`s Cousin Eddie', 
        country='US', 
        area='*', 
        aka='Sasquatch'
    )
]


def find(name: str) -> Creature | None: 
    for c in _creatures: 
        if c.name == name: 
            return c 
        else: 
            return None 



def get_all() -> list[Creature]: 
    
    return _creatures; 


def get_one(name: str) -> Creature: 
    c = find(name) 
    if c is None: 
        raise Missing('{name} is missing error')
    
    return c 


def create(creature: Creature) -> Creature: 
    c = find(creature.name) 
    if c: 
        raise Duplicate('{creature.name} duplicate error')
    
    _creatures.append(creature) 
    return creature 



def modify(name: str, creature: Creature) -> Creature: 
    c = find(name) 
    if c is None: 
        raise Missing('{name} missing error')
    return creature




def delete(name: str) -> None: 
    c = find(name) 
    if c is None: 
        raise Missing(f'creature: {name} missing error ') 
    
    _creatures.remove(c); 
    return None 




